<template>
	<view class="scan-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="false" color="#fff" title="扫码签到"></uni-navbar></view>

		<view class="container">
			<view class="img-box"><image class="image" src="/static/img/sys.png" mode="widthFix"></image></view>
			<view class="fiexd-btm"><u-button class="form-btn" type="error" @click="qrcodeComplete2">扫一扫</u-button></view>
		</view>

		<view class="p-popup" v-if="show" @click="show = false">
			<view class="image-box">
				<view class="bg-image"><image class="image" src="/static/img/bg_02.png" mode="widthFix"></image></view>
				<view class="content">
					<view class="title clamp2">{{ meetingInfo.title }}</view>
					<view class="name clamp">姓名：{{ meetingInfo.userName }}</view>
					<view class="info">
						<view class="text" v-show="meetingInfo.seatNo != '暂无安排'">座位信息：{{ $htmlRegx(meetingInfo.seatNo) }}</view>
						<view class="text" v-show="meetingInfo.carNo != '暂无安排'">车辆信息：{{ $htmlRegx(meetingInfo.carNo) }}</view>
						<view class="text" v-show="meetingInfo.hotelNo != '暂无安排'">房间信息：{{ $htmlRegx(meetingInfo.hotelNo) }}</view>
						<view class="text" v-show="meetingInfo.dinnerInfo != '暂无安排'">就餐信息：{{ $htmlRegx(meetingInfo.dinnerInfo) }}</view>
						<!-- <view class="text" v-show="!meetingInfo.firstSign && meetingInfo.signTime">签到时间：{{ meetingInfo.signTime }}</view> -->
					</view>

					<view class="btn"><image class="image" src="/static/img/bg_04.png" mode="widthFix"></image></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			show: false,
			meetingInfo: {}
		};
	},
	onLoad() {
		this.loadLogin();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				uni.scanCode({
					onlyFromCamera: true,
					success: (res) => {
						this.qrcodeResult(res);
					}
				});
			} else {
				this.$logout();
			}
		},
		qrcodeComplete2(e) {
			uni.scanCode({
				onlyFromCamera: true,
				success: (res) => {
					this.qrcodeResult(res);
				}
			});
		},
		qrcodeResult(res) {
			try {
				let resulet = JSON.parse(res.result);
				if (resulet.type == 'huiyi') {
					let typeMap = {
						1: '扫码签到',
						2: '刷脸签到',
						3: '手动签到',
						4: '代为签到'
					};
					let data = {
						signType: '1',
						meetingId: resulet.data.id,
						userId: this.userId
					};
					this.$request('/huiyihuodong/hyhd-meeting-user/signTime', data, {
						load: true
					}).then((res) => {
						this.meetingInfo = res.data;
						this.show = true;
						return false;
						if (!res.data.firstSign) {
							uni.showModal({
								title: '已通过' + typeMap[res.data.signType],
								content: '签到时间：' + res.data.signTime,
								complete: () => {}
							});
						}
					});
				} else if (resulet.type == 'xsys') {
					let data = {
						consultSign: {
							infoid: resulet.data.id,
							userId: this.userId,
							userName: this.userName
						}
					};
					this.$request('/xieshangyishi/consultSign/sign/add', data, {
						load: true
					}).then((res) => {
						this.$msg('签到成功！');
					});
				} else if (resulet.type == 'loginQr') {
					let data = {
						step: '3',
						qrId: resulet.data.id,
						userId: this.userId
					};
					this.$request('/loginQr', data, {
						load: true
					}).then((res) => {
						uni.navigateTo({
							url: '/pages/login/qrcode?qrId=' + resulet.data.id
						});
					});
				} else {
					this.$msg(resulet);
				}
			} catch (e) {
				this.$msg('扫码失败！');
			}
		}
	}
};
</script>

<style lang="scss">
.img-box {
	position: relative;
	padding: 100rpx 30rpx;

	.image {
		margin: 0 auto;
		width: 510rpx;
	}
}

.p-popup {
	position: fixed;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: 1000;
	background: rgba(0, 0, 0, 0.59);

	.image-box {
		position: relative;
		margin: 0 auto;
		padding-top: 252rpx;
		width: 588rpx;

		.bg-image {
			position: absolute;
			left: 0;
			top: 0;
			right: 0;
			width: 588rpx;
		}

		.image {
			width: 588rpx;
		}

		.content {
			position: relative;
			z-index: 11;
			text-align: center;
		}

		.info {
			min-height: 150rpx;
			border-left: 14rpx solid #ffeece;
			border-right: 14rpx solid #ffeece;
			background: #fff repeat-y center top;
			background-image: url('/static/img/bg_03.png');
			background-size: 100% auto;
			background-origin: border-box;
		}

		.title {
			margin: 0 30rpx 84rpx;
			min-height: 100rpx;
			font-size: 18px;
			color: #e5231a;
			line-height: 50rpx;
		}

		.name {
			margin: 0 30rpx 30rpx;
			font-size: 15px;
			color: #792d28;
			line-height: 42rpx;
		}

		.text {
			padding: 0 30rpx 10rpx;
			font-size: 13px;
			color: #666;
			line-height: 36rpx;
		}
	}
}
</style>
